package com.example.su_shi_tan_bas_lib.constant

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import androidx.fragment.app.Fragment
import androidx.navigation.NavOptions
import com.example.su_shi_tan_bas_lib.R

fun getDefaultNavOptions(): NavOptions = NavOptions.Builder()
    .setEnterAnim(R.anim.h_fragment_enter)
    .setExitAnim(R.anim.h_fragment_exit)
    .setPopEnterAnim(R.anim.h_fragment_pop_enter)
    .setPopExitAnim(R.anim.h_fragment_pop_exit)

    .build()

const val DATA_STREAM = "data_stream"

const val BUNDLE_WRAPPER = "bundle_wrapper"

fun <T> putData(t: T): Bundle = Bundle().apply { putSerializable(DATA_STREAM, PagerData(t)) }


fun <T> Fragment.getPageData(): T = arguments?.get(DATA_STREAM) as T


fun <T> Activity.entryPage(clazz: Class<out Activity>, t: T) =
    apply {
        val intent = Intent(this, clazz)
        intent.putExtra(DATA_STREAM, PagerData(t))
        startActivity(intent)
    }

fun <T> Activity.getPageData(): T {
    val pagerData = intent.getSerializableExtra(DATA_STREAM) as PagerData<T>
    return pagerData.t
}